﻿using Autofac.Integration.Web.Forms;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Timesheet.Service;
using Timesheet.Common;
using Timesheet.Domain;

namespace Timesheet.WebForm.Account
{
    public partial class ChangePass : Page
    {
        private static readonly ILog logger = LogManager.GetLogger(typeof (ChangePass));

        public IUserService UserService { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void ASPxBtnLogin_Click(object sender, EventArgs e)
        {
            long userInfoId = Int64.Parse("" + Session["UserId"]);

            User userInfo = UserService.GetUserById(userInfoId);

            if (userInfo != null)
            {
                if (PasswordUtils.getHashPassword(cPassword.Text) == userInfo.Password)
                {
                    userInfo.Password = tbPassword.Text;
                    UserService.Update(userInfo);
                    ASPxLbMessage.Text = "Change password successfully";
                }
                else
                {
                    ASPxLbMessage.Text = "Current Password is incorrect";

                }

                ASPxLbMessage.Visible = true;
            }
            else
                Response.Redirect("~/Account/Login.aspx");
        }
    }
}

   